package com.otomotion.research.ants.io;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;

import com.otomotion.research.ants.information.Coordinate;


public class VClient {

	Document d = new Document();
	

	public static void main(String[] args) {
		new VClient().send();
	}
	
	public void send() {
		d.setRootElement(new Element("root"));
		try {


			byte[] udpMsg = RequestFactory.getData(new Coordinate(10,10,10), 5).getBytes();
			System.out.println(new String(udpMsg));
			InetAddress addr = InetAddress.getByName("localhost");
			DatagramPacket packet = new DatagramPacket(udpMsg, udpMsg.length,
					addr, 8888);
			DatagramSocket datagramSocket = new DatagramSocket();
			datagramSocket.send(packet);

			byte[] dataArray = packet.getData();
			for (int cnt = 0; cnt < packet.getLength(); cnt++)
				dataArray[cnt] = 'x';
			System.out.println(new String(packet.getData()));
			datagramSocket.receive(packet);
			System.out.println(new String(packet.getData()));
			datagramSocket.close();
		}// end try
		catch (UnknownHostException e) {
			System.out.println(e);
			System.out.println("Connection Failure. Are you online?");
		}// end catch UnknownHostException

		catch (SocketException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		}
	}
}
